﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Model;

namespace DAL
{
    public class UserInfoDAL
    {
        public static List<hus> showwangshangyuding(string mid)
        {
            string sqlstr = "select * from Personal a,make b,roominfo c,roomtypes d where a.mid=@mid and b.rommid=c.rid and c.rid=d.roomtid";
            SqlParameter[] para = new SqlParameter[]
            {
                    new SqlParameter("@mid",mid),
                };
            SqlDataReader reader = DBhelper.ExecuteReaders(sqlstr, para);
            List<hus> list = new List<hus>();
            while (reader.Read())
            {
                hus h = new hus();
                h.cid = Convert.ToInt32(reader["cid"]);
                h.nameper = reader["nameper"].ToString();
                h.roomtype= reader["roomtype"].ToString();
                h.price = Convert.ToInt32(reader["price"]);
                h.begtime = Convert.ToDateTime(reader["begtime"]);
                h.endtime = Convert.ToDateTime(reader["endtime"]);
                h.people = Convert.ToInt32(reader["people"]);
                h.roomhao = Convert.ToInt32(reader["roomhao"]);
                h.zhuangtai = Convert.ToInt32(reader["zhuangtai"]);
            }
            reader.Close();
            return list;
        }
        public static DataTable showuserinfo()
        {
            string sqlsrt = "select * from Personal";
            return DBhelper.GetDataTable(sqlsrt);
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public static int deleteuserinfo(int cid)
        {
            string sqlset = "delete from Personal where cid='"+cid+"'";
            return DBhelper.GetExecuteNonQuery(sqlset);
        }
        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static int adduserinfo(Personalmodel p)
        {
            string sqlstr =string.Format("insert into Personal values('{0}','{1}','{2}','{3}','{4}','{5}')",p.nameper,p.nid,p.Sex,p.tel,p.pwd,p.mid);
            return DBhelper.GetExecuteNonQuery(sqlstr);
        }
    }
}
